//
//  VC_Search.m
//  yjw-winner
//
//  Created by 隆霁 on 2018/9/21.
//  Copyright © 2018年 Shanghai decade financial information service co., LTD. All rights reserved.
//

#import "VC_Search.h"
#import "Cell_Search.h"

static NSString *identifier = @"search_cell_identifier";
@interface VC_Search ()<UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource> {
    
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic, strong) NSArray *dataArray;
@end

@implementation VC_Search
- (NSArray *)dataArray {
    return @[@"",
             @""];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"取消" forState:UIControlStateNormal];
    UISearchBar * searchbar = [[UISearchBar alloc]init];
    searchbar.delegate = self;
    [searchbar setPlaceholder:@"搜索老师或者课程名称"];
    [self.navigationController.navigationBar addSubview:searchbar];
    
    button.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - 5 - 5 - 40, 0, 40, 44);
    searchbar.tintColor = [UIColor lightGrayColor];
    
    searchbar.frame = CGRectMake(5, 0, [UIScreen mainScreen].bounds.size.width - 5 - 5 - 5 - 40, 44);
    [self.navigationController.navigationBar addSubview:button];
    [button setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(cancelButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self initTableView];
}

- (void)initTableView {
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([Cell_Search class]) bundle:[NSBundle mainBundle]] forCellReuseIdentifier:identifier];
    self.tableView.tableFooterView = [UIView new];
    self.tableView.tableHeaderView = [UIView new];
}

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
    return YES;
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
    [self.view endEditing:YES];
}

#pragma mark --mark UITableViewDelegate UITableViewDataSource

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    Cell_Search *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100.0f;
}


- (void)cancelButtonClick:(UIButton *)sender {
    [self dismissViewControllerAnimated:NO completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
